package com.sushi.bigblog.utils;

/**
 * User: bianpeng
 * Date: 11-12-20
 */
public class Buffer {
    private byte[] buf;

    public Buffer(int size) {
        buf = new byte[size];
    }
    public Buffer() {
        this(32);
    }

    /**
     * 十进制写入一个整数
     * @param val 整数
     * @return buffer中的起始位置
     */
    public int print(int val) {
        int i = buf.length - 1;
        for(; i >= 0; --i) {
            buf[i] = (byte)('0' + (val % 10));
            val /= 10;
            if (val == 0) break;
        }
        return i;
    }

    public byte[] buf() {
        return buf;
    }

    public int size() {
        return buf.length;
    }
}
